﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using DevExpress.XtraEditors;
using MyUtils;
using Resources;
namespace CoffeeManager
{
    public partial class MyMessageFrm : DevExpress.XtraEditors.XtraForm
    {
        #region Properties for messagebox
        ArrayList arrButtons = new ArrayList();
        String messageText;
        MyMessageBoxResults myMessageResult= MyMessageBoxResults.Cancel;
         
        MyMessageBoxResults[] arrMyMessageResults ={MyMessageBoxResults.Abort,MyMessageBoxResults.Cancel,
                                                       MyMessageBoxResults.Ignore,MyMessageBoxResults.No,MyMessageBoxResults.OK,
                                                       MyMessageBoxResults.Retry,MyMessageBoxResults.Yes};
        String[] arrButtonStringId ={ResourceIDs.STR_ABORT,ResourceIDs.STR_CANCEL,ResourceIDs.STR_IGNORE,
                                        ResourceIDs.STR_NO,ResourceIDs.STR_OK,ResourceIDs.STR_RETRY,ResourceIDs.STR_YES};
                                        
      
        
        public String MessageText
        {
            get { return messageText; }
            set { 
                messageText = value;
                rtcontentMessage.Text = value;
            }
        }
        String messageCaption;

        public String MessageCaption
        {
            get { return messageCaption; }
            set { messageCaption = value;
            this.Text = value;
            }
        }
        #endregion 
        
        public MyMessageFrm()
        {
            InitializeComponent();
        }

        #region Show dialog
        public MyMessageBoxResults ShowMyMessageBox()
        {
            this.ShowDialog();
            return myMessageResult;
        }
        #endregion 

        
        #region LoadButton
        public void CreateButtonList()
        {

            for (int i = 0; i < MYMESSAGEBOX_NUMBER.INT_BUTTONS; i++)
            {
                SimpleButton spbutton = new SimpleButton();
                spbutton.Text = ResourceHelper.LoadString(arrButtonStringId[i]);
                spbutton.Tag = arrMyMessageResults[i];
                spbutton.Click+=new EventHandler(button_Event);
                arrButtons.Add(spbutton);
            }
        }
        /// <summary>
        /// Get button from array list
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        SimpleButton GetButtonFromArrayList(MyMessageBoxResults result)
        {

            for (int i = 0; i < MYMESSAGEBOX_NUMBER.INT_BUTTONS; i++)
            {
                SimpleButton sbutton = (SimpleButton)arrButtons[i];
                MyMessageBoxResults eq = (MyMessageBoxResults)Enum.Parse(typeof(MyMessageBoxResults), sbutton.Tag.ToString());
                if (result.Equals(eq))
                    return sbutton;
            }
            return null;
        }
        /// <summary>
        /// Set button is messagebox form
        /// </summary>
        /// <param name="buttons"></param>
        public void SetButtons(MyMessageBoxButtons buttons)
        {
            
        
            switch (buttons)
            {
                case MyMessageBoxButtons.AbortRetryIgnore:
                    {
                        pnbuttons.Size = MYMESSAGEBOX_NUMBER.SIZE_PANEL_THREE_BUTTONS;
                        pnbuttons.Location = MYMESSAGEBOX_NUMBER.POINT_PANEL_THREE_BUTTONS;
                        SimpleButton btnAbort = GetButtonFromArrayList(MyMessageBoxResults.Abort);
                        SimpleButton btnRetry = GetButtonFromArrayList(MyMessageBoxResults.Retry);
                        SimpleButton btnIgnore = GetButtonFromArrayList(MyMessageBoxResults.Ignore);
                        btnRetry.Location = MYMESSAGEBOX_NUMBER.POINT_DELAY_WIDTH;
                        btnIgnore.Location = MYMESSAGEBOX_NUMBER.POINT_TWO_DELAY_WIDTH;
                        pnbuttons.Controls.Add(btnAbort);
                        pnbuttons.Controls.Add(btnRetry);
                        pnbuttons.Controls.Add(btnIgnore);
                        break;
                    }
                case MyMessageBoxButtons.OK:
                    {
                        pnbuttons.Size = MYMESSAGEBOX_NUMBER.SIZE_PANEL_ONE_BUTTONS;
                        pnbuttons.Location = MYMESSAGEBOX_NUMBER.POINT_PANEL_ONE_BUTTONS;
                        SimpleButton btnOk = GetButtonFromArrayList(MyMessageBoxResults.OK);
                        pnbuttons.Controls.Add(btnOk); 
                        break;
                    }
                case MyMessageBoxButtons.OKCancel:
                    {
                        pnbuttons.Size = MYMESSAGEBOX_NUMBER.SIZE_PANEL_TWO_BUTTONS;
                        pnbuttons.Location = MYMESSAGEBOX_NUMBER.POINT_PANEL_TWO_BUTTONS;
                        SimpleButton btnOK = GetButtonFromArrayList(MyMessageBoxResults.OK);
                        SimpleButton btnCancel = GetButtonFromArrayList(MyMessageBoxResults.Cancel);
                        btnCancel.Location = MYMESSAGEBOX_NUMBER.POINT_DELAY_WIDTH;
                        pnbuttons.Controls.Add(btnOK);
                        pnbuttons.Controls.Add(btnCancel);

                        break;
                    }
                case MyMessageBoxButtons.RetryCancel:
                    {
                        pnbuttons.Size = MYMESSAGEBOX_NUMBER.SIZE_PANEL_TWO_BUTTONS;
                        pnbuttons.Location = MYMESSAGEBOX_NUMBER.POINT_PANEL_TWO_BUTTONS;
                        SimpleButton btnRetry = GetButtonFromArrayList(MyMessageBoxResults.Retry);
                        SimpleButton btCancel = GetButtonFromArrayList(MyMessageBoxResults.Cancel);
                        btCancel.Location = MYMESSAGEBOX_NUMBER.POINT_DELAY_WIDTH;
                        pnbuttons.Controls.Add(btnRetry);
                        pnbuttons.Controls.Add(btCancel);
                        break;
                    }
                case MyMessageBoxButtons.YesNo:
                    {
                        pnbuttons.Size = MYMESSAGEBOX_NUMBER.SIZE_PANEL_TWO_BUTTONS;
                        pnbuttons.Location = MYMESSAGEBOX_NUMBER.POINT_PANEL_TWO_BUTTONS;
                        SimpleButton btnYes = GetButtonFromArrayList(MyMessageBoxResults.Yes);
                        SimpleButton btnNo = GetButtonFromArrayList(MyMessageBoxResults.No);
                        btnNo.Location = MYMESSAGEBOX_NUMBER.POINT_DELAY_WIDTH;
                        pnbuttons.Controls.Add(btnYes);
                        pnbuttons.Controls.Add(btnNo);
                        break;
                    }
                     
                case MyMessageBoxButtons.YesNoCancel:
                    {
                        pnbuttons.Size = MYMESSAGEBOX_NUMBER.SIZE_PANEL_THREE_BUTTONS;
                        pnbuttons.Location = MYMESSAGEBOX_NUMBER.POINT_PANEL_THREE_BUTTONS;
                        SimpleButton btnYes = GetButtonFromArrayList(MyMessageBoxResults.Yes);
                        SimpleButton btnNo = GetButtonFromArrayList(MyMessageBoxResults.No);
                        SimpleButton btnCancel = GetButtonFromArrayList(MyMessageBoxResults.Cancel);
                        btnNo.Location = MYMESSAGEBOX_NUMBER.POINT_DELAY_WIDTH;
                        btnCancel.Location = MYMESSAGEBOX_NUMBER.POINT_TWO_DELAY_WIDTH;
                        pnbuttons.Controls.Add(btnYes);
                        pnbuttons.Controls.Add(btnNo);
                        pnbuttons.Controls.Add(btnCancel);
                        break;
                    }
            }
        }
        
        #endregion
        /// <summary>
        /// Load bitmap for picture box
        /// </summary>
        /// <param name="messIcon"></param>
        #region Loadbitmap for picturebox
        public void SetPicture(MyMessageBoxIcons messIcon)
        {
            switch (messIcon)
            {
                case MyMessageBoxIcons.Error:
                    pictureEdit.Image =ResourceHelper.Get_Convert_BitMap(ResourceIDs.BITMAP_ERROR);
                    break;
                case MyMessageBoxIcons.Question:
                    pictureEdit.Image = ResourceHelper.Get_Convert_BitMap(ResourceIDs.BITMAP_QUESTION);
                    break;
                case MyMessageBoxIcons.Information:
                    pictureEdit.Image = ResourceHelper.Get_Convert_BitMap(ResourceIDs.BITMAP_INFORMATION);
                    break;
                case MyMessageBoxIcons.Warning:
                    pictureEdit.Image = ResourceHelper.Get_Convert_BitMap(ResourceIDs.BITMAP_WARNING);
                    break;
            }
        }
        #endregion


        /// <summary>
        /// Load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Event
        
        private void button_Event(object sender, EventArgs e)
        {
            myMessageResult = (MyMessageBoxResults)((SimpleButton)sender).Tag;
            this.Close();
        }
        #endregion 
    }
}
